//
//  BookJourneySectionCell.m
//  FreeTrip
//
//  Created by 352324497@qq.com on 15/11/27.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "BookJourneySectionCell.h"

@implementation BookJourneySectionCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        CGFloat photoHeight = KScreenWidth / 630 * 330;
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10 * KScreenWidth/ 375, KScreenWidth, 30 * KScreenWidth / 375)];
//        self.titleLabel.backgroundColor = [UIColor grayColor];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = [UIFont systemFontOfSize:18 weight:0.01];
        [self.contentView addSubview:_titleLabel];
        
        self.photoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 50 * KScreenWidth / 375, KScreenWidth, photoHeight)];
        [self.contentView addSubview:_photoImageView];
        
        self.tripLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * KScreenWidth / 375, 60 * KScreenWidth / 375 + photoHeight, KScreenWidth - 20 * KScreenWidth / 375, 10 * KScreenWidth / 375)];
        self.tripLabel.numberOfLines = 0;
//        self.tripLabel.backgroundColor = [UIColor redColor];
        self.tripLabel.font = [UIFont systemFontOfSize:16 * KScreenWidth / 375];
       [self.contentView addSubview:_tripLabel];
    }
    return self;
}

-(void)setModel:(BookJournDetailNodesModel *)model
{
    CGFloat photoHeight = KScreenWidth / 630 * 330;
    
    _model = model;
    [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.tripLabel.text = model.tips;
    CGRect bounds = [model.tips boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    self.tripLabel.frame = CGRectMake(10 * KScreenWidth / 375,  60 * KScreenWidth / 375 + photoHeight, KScreenWidth - 20 * KScreenWidth / 375, bounds.size.height + 5);
}

+(CGFloat)heightForCell:(BookJournDetailNodesModel *)model
{
    CGRect bounds = [model.tips boundingRectWithSize:CGSizeMake(KScreenWidth - 20 * KScreenWidth / 375, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    
    CGFloat photoHeight = KScreenWidth / 630 * 330;
    
    return photoHeight + bounds.size.height + 70 * KScreenWidth / 375;

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
